﻿@typeparam T

<div>
    <div class="bricklist">
        @foreach( var item in Items.Where( x => x != null ) )
        {
            @if( item != null )
            {
                <div class="bricktext">
                    <div class="bricktext-label">@ToStrFunc(item)</div>
                    @if( ItemRemoved != null )
                    {
                        <div class="deletebrick" title="@RemoveText(item)" @onclick="@(() => ItemRemoved(item))">
                            <i class="fa fa-times-circle"/>
                        </div>
                    }
                </div>
            }
        }
    </div>
</div>

@code {

    [Parameter] public IEnumerable<T> Items { get; init; }

    [Parameter] public Action<T> ItemRemoved { get; init; } = null;

    [Parameter] public Func<T, string> ToStrFunc { get; init; } = x => x?.ToString();

    [Parameter] public string RemoveLabel { get; init; } = "Remove";

    private string RemoveText(T x)
    {
        return $"{RemoveLabel} {ToStrFunc(x)}";
    }

}